const mongoose = require('./db')
const Schema = mongoose.Schema


const huaSchema = new Schema({
    title: { type: String, default: '' },
    img: { type: String, default: '' },
    hot: { type: Number, default: 0 },
    viewCount: { type: Number, default: 0 },
    content: { type: String, default: '' },
})
const dongtaiSchema = new Schema({
    userId: { type: String, required: true },
    huaId: { type: String, required: true },
    schoolId: { type: String, required: true },
    title: { type: String, default: '' },
    publishTime: { type: Date, default: Date.now },
    likeCount: { type: Number, default: 0 },
    commentCount: { type: Number, default: 0 },
    shareCount: { type: Number, default: 0 },
    media: { type: [String], default: [] }, // 存储图片或视频URL数组
    comments: [{ 
        _id: { type: mongoose.Schema.Types.ObjectId, default: () => new mongoose.Types.ObjectId() },
        userId: { type: String, required: true },
        username: { type: String, required: true },
        content: { type: String, required: true, trim: true },
        likeCount: { type: Number, default: 0 },
        createdAt: { type: Date, default: Date.now }
    }]
})
const Hua = mongoose.model('hua', huaSchema, 'hua')
const Dongtai = mongoose.model('dongtai', dongtaiSchema, 'dongtai')
const confessionSchema = new Schema({
    content: { type: String, required: true, trim: true },
    publishTime: { type: Date, default: Date.now },
    likeCount: { type: Number, default: 0 },
    category: { type: String, enum: ['normal', '校花', '校草'], default: 'normal' }, // 表白分类
    voteCount: { type: Number, default: 0 }, // 投票数
    comments: [{ 
        content: { type: String, required: true, trim: true },
        publishTime: { type: Date, default: Date.now }
    }]
});
const Confession = mongoose.model('confession', confessionSchema, 'confessions');

module.exports = {
    Hua, Confession, Dongtai
}